<?php
class Biografi{
	public $no_pancang; // id
	
	public $no_individu;
	public $tgl_penanaman;
	public $usia;
	public $replika;
	public $cross_asal;
	public $jenis;
	
	function Biografi($db,$id){
		$this->no_pancang = $id;
		$this->db = $db;
		$this->process();
	}
	
	function getNoIndividu($no_pancang){
		$q = "SELECT 
                `no_individu` 
            FROM 
                `caramel_managerial`.`pancang` 
            WHERE `no_pancang`='$no_pancang'";
		
		return $this->db->get_var($q);
	}
	
	private function process(){
		$this->no_individu = $this->getNoIndividu($this->no_pancang);
		
		$query = "
			SELECT 
				`no_pancang`, 
				`tgl_penanaman`, 
				`replika`,
				DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(tgl_penanaman, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(tgl_penanaman, '00-%m-%d'))+usia_saat_tanam AS usia, 
				`cross_asal_pokok`, 
				`jenis_tanaman` 
			FROM `caramel_managerial`.`biodata_tanaman` 
            WHERE `no_individu`='".$this->no_individu."'";
		$result= $this->db->get_results($query, ARRAY_A);
		
		if( $result ){
			$result = $result[0];			
			// storing
			$this->tgl_penanaman	= $result['tgl_penanaman'];
			$this->usia			= $result['usia'];
			$this->replika		= $result['replika'];
			$this->cross_asal	= $result['cross_asal_pokok'];
			$this->jenis		= $result['jenis_tanaman'];
		}
		else{
			return NULL;
		}
	}
}
?>